import request from '@/utils/request';
import { AxiosPromise } from 'axios';
/**
 * 查询跟物品有关的订单列表
 * @param query
 * @returns {*}
 */
export const listOrder = (query?: OrderVO): AxiosPromise<OrderVO[]> => {
  return request({
    url: '/wms/order/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询跟物品有关的订单详细
 * @param id
 */
export const getOrder = (id: number): AxiosPromise<OrderVO> => {
  return request({
    url: '/wms/order/' + id,
    method: 'get'
  });
};

/**
 * 新增跟物品有关的订单
 * @param data
 */
export const addOrder = (data: OrderVO) => {
  return request({
    url: '/wms/order',
    method: 'post',
    data: data
  });
};

/**
 * 修改跟物品有关的订单
 * @param data
 */
export const updateOrder = (data: OrderVO) => {
  return request({
    url: '/wms/order',
    method: 'put',
    data: data
  });
};

/**
 * 执行订单
 * @param data
 */
export const execOrder = (data: OrderVO) => {
  return request({
    url: '/wms/order/execOrder',
    method: 'put',
    data: data
  });
};

/**
 * 转采购订单
 * @param data
 */
export const turnOrder = (data: OrderVO[]) => {
  return request({
    url: '/wms/order/turnOrder',
    method: 'put',
    data: data
  });
};

/**
 * 冲销订单
 * @param data
 */
export const backOrder = (data: OrderVO) => {
  return request({
    url: '/wms/order/backOrder',
    method: 'put',
    data: data
  });
};

/**
 * 财务结算
 * @param data
 */
export const FinancialSettlement = (data: OrderVO) => {
  return request({
    url: '/wms/order/financialSettlement',
    method: 'put',
    data: data
  });
};

/**
 * 删除跟物品有关的订单
 * @param id
 */
export const delOrder = (id: number | Array<number>) => {
  return request({
    url: '/wms/order/' + id,
    method: 'delete'
  });
};

export const listOrderLine = (query?: OrderLineVO): AxiosPromise<OrderLineVO[]> => {
  return request({
    url: '/wms/order/lineList',
    method: 'get',
    params: query
  });
};

/**
 * 删除测试子
 * @param lineId
 */
export const delOrderLine = (lineId: number | Array<number>) => {
  return request({
    url: '/wms/order/lineId/' + lineId,
    method: 'delete'
  });
};

export interface OrderVO extends BaseEntity, PageQuery {

  id?: number;

  name?: string;

  /** 作业类型in：入库，out：出库，nothing：不操作库存 */
  wmsType?: string;

  typeId?: number;
  typePage?: string;
  typeName?: string;

  partnerName?: string;
  partnerId?: number | string;
  selfWhId?: number;
  otherWhId?: number;
  status?: string;
  //退回单据号
  backId?: number;
  sourceId?: number;
  manufacturerId?: number;
  applicantId?: number;
  execId?: number;
  remark?: string;

  totalMoney?: number;
  discountMoney?: number;
  costMoney?: number;

  line?: OrderLineVO[];

  warehouseName?: string;

  fmsAccount?: number;
}

export interface OrderLineVO extends BaseEntity, PageQuery {
  id?: number;
  lineId?: number;
  name?: string;

  /** 作业类型in：入库，out：出库，nothing：不操作库存 */
  wmsType?: string;
  //产品Id
  productId?: number;
  //产品名称
  productName?: string;
  //批次号
  batchCode?: string;
  //单位
  measureUnit?: string;
  //售价
  price?: number;
  //成本价
  purchasePrice?: number;
  //数量
  quantity?: number;
  //仓库Id
  whId?: number;
  //仓库分区Id
  areaId?: number;
  //总金额
  totalMoney?: number;
  //优惠金额
  discountMoney?: number;
  //应收金额
  costMoney?: number;
  //到期时间
  expireDate?: any;
  //仓库总量
  maxQuantity?: number;
  //仓库名称
  whName?: string;
  //库存总量
  stockQuantity?: number;
}


//=============================OrderType============
/**
 * 查询产品入库录列表
 * @param query
 * @returns {*}
 */

export const listOrderType = (query?: OrderTypeVO): AxiosPromise<OrderTypeVO[]> => {
  return request({
    url: '/wms/orderType/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询产品入库录详细
 * @param typeId
 */
export const getOrderType = (typeId: number): AxiosPromise<OrderTypeVO> => {
  return request({
    url: '/wms/orderType/' + typeId,
    method: 'get'
  });
};

/**
 * 新增产品入库录
 * @param data
 */
export const addOrderType = (data: OrderTypeVO) => {
  return request({
    url: '/wms/orderType',
    method: 'post',
    data: data
  });
};

/**
 * 修改产品入库录
 * @param data
 */
export const updateOrderType = (data: OrderTypeVO) => {
  return request({
    url: '/wms/orderType',
    method: 'put',
    data: data
  });
};

/**
 * 删除产品入库录
 * @param typeId
 */
export const delOrderType = (typeId: number | Array<number>) => {
  return request({
    url: '/wms/orderType/' + typeId,
    method: 'delete'
  });
};

export interface OrderTypeVO extends BaseEntity, PageQuery {
  /** 库存作业编码 */
  typeId?: number;

  /** 名称 */
  name?: string;

  /** 展示页面 */
  page?: string;

  /** 退回单据类别 */
  backId?: number;

  /** 退回单据类别 */
  backName?: string;

  /** 下步单据类别 */
  nextId?: number;

  /** 作业类型in：入库，out：出库，nothing：不操作库存 */
  wmsType?: string;

  /** 财务类型in：入库，out：出库，nothing：不操作库存 */
  fmsType?: string;

  /** 财务记账科目 */
  classificationCode?: string;

  /** 财务记账科目名称 */
  classificationName?: string;

  /** 状态 */
  status?: string;

  /** 审批流程 */
  workflowId?: number;
}
